import request from '@/utils/request'

/**
 * 查询运输订单列表
 * @param {Object} query - 查询参数，包括分页、筛选条件等
 * @returns {Promise} - 返回运输订单数据和分页信息
 */
export function listTransport(query) {
    return request({
        url: '/delivery/transportOrder/list',
        method: 'get',
        params: query,
    });
}

/**
 * 新增运输订单
 * @param {Object} data - 运输订单信息
 * @returns {Promise} - 返回新增结果
 */
export function addTransport(data) {
    return request({
        url: '/delivery/transportOrder/add',
        method: 'post',
        data,
    });
}

/**
 * 更新运输订单
 * @param {Object} data - 运输订单信息
 * @param {String} approach - 变更方式
 * @returns {Promise} - 返回更新结果
 */
export function updateTransport(data, approach) {
    return request({
        url: '/delivery/transportOrder/update',
        method: 'put',
        params: { approach },
        data,
    });
}

/**
 * 删除运输订单
 * @param {String} trackingNumber - 运输订单号
 * @returns {Promise} - 返回删除结果
 */
export function deleteTransport(trackingNumber) {
    return request({
        url: `/delivery/transportOrder/delete`,
        method: 'delete',
        params: { trackingNumber },
    });
}

/**
 * 获取运输订单详情
 * @param {String} trackingNumber - 运输订单号
 * @returns {Promise} - 返回运输订单详情
 */
export function getTransportDetail(trackingNumber) {
    return request({
        url: `/delivery/transportOrder/details`,
        method: 'get',
        params: { trackingNumber },
    });
}

/**
 * 确认运输订单
 * @param {String} trackingNumber - 运输订单号
 * @returns {Promise} - 返回确认结果
 */
export function confirmTransport(trackingNumber) {
    return request({
        url: `/delivery/transportOrder/confirm`,
        method: 'put',
        params: { trackingNumber },
    });
}

/**
 * 生成配送单
 * @param {String} logisticId - 物流公司ID
 * @param {List<String>} trackingNumbers - 运输订单号列表
 * @param {List<String>} excludeVehicleNos - 排除车辆号列表
 * @returns {Promise} - 返回生成结果
 */
export function generateDelivery(logisticId, trackingNumbers, excludeVehicleNos) {
    /* exclusionVehicle, trackingNumberList*/
    return request({
        url: `/delivery/transportOrder/generateDeliveryOrder`,
        method: 'post',
        data: {
            logisticDeliver: logisticId,
            exclusionVehicle: excludeVehicleNos,
            trackingNumberList: trackingNumbers,
        },
    });
}

/**
 * 筛选运输订单明细
 * @param {String} trackingNumber - 运输订单号
 * @param {Object} query - 查询参数，包括筛选条件等
 * @returns {Promise} - 返回筛选结果
 */
export function getFilteredTransportDetail(trackingNumber,query) {
    return request({
        url: `/delivery/transportDetail/filter/${trackingNumber}`,
        method: 'get',
        params: query
    });
}

export function getDetailsByOrderNumber(orderNumber) {
    return request({
        url: `/delivery/transportDetail/order/${orderNumber}`,
        method: 'get'
    });
}

export function updateArrivalTime(trackingNumber, departureDate) {
    return request({
        url: '/delivery/transportOrder/updateArrivalTime',
        method: 'put',
        params: { trackingNumber, departureDate },
    });
}

// export function getDetailsByOrderNumber(orderNumber) {
//     return request({
//         url: `/delivery/transportDetail/order/${orderNumber}`,
//         method: 'get'
//     });
// }

